package net.arvin.service;

import org.apache.http.Header;

import com.loopj.android.http.TextHttpResponseHandler;

import net.arvin.dao.ResponseHandler;
import net.arvin.utils.HttpRequestClient;
import net.arvin.view.LoadingView;
import android.content.Context;
import android.widget.Toast;

public class RechargeService {
	public static void tryRechargeMoney(final String rechargeJson,
			final ResponseHandler handler, final Context context) {
		LoadingView.show(context, "充值中...");
		HttpRequestClient.startPostRechargeRequest(rechargeJson,
				new TextHttpResponseHandler() {
					@Override
					public void onFailure(int statusCode, Header[] headers,
							String responseBody, Throwable error) {
						LoadingView.dismiss();
						if (responseBody == null) {
							Toast.makeText(context, "连接超时=_=!",
									Toast.LENGTH_SHORT).show();
						}
					}

					@Override
					public void onSuccess(int statusCode, Header[] headers,
							String responseBody) {
						LoadingView.dismiss();
						if (responseBody.equals("")) {
							handler.onRequestFailed(responseBody);
						} else {
							handler.onRequsetSucceeded(responseBody);
						}
					}
				}, context);
	}
}
